package gameEngine;

import classInterfaces.ILine;
import gameEngine.Dot;
import Exceptions.IncorrectInputException;

public class Line implements ILine {
	Dot start;
	Dot end;

	/**
	 * 
	 * @param start
	 * @param end
	 * @param isTheLineUp
	 *            - adding extra parameter, because it is unknown which way is
	 *            the second dot from the first(if isTheLineUp == false then the
	 *            second dot is right to the first)
	 * @throws IncorrectInputException
	 */
	Line(Dot start, Dot end, boolean isTheLineUp)
			throws IncorrectInputException {
		if (start == null || end == null) {
			throw new IncorrectInputException("can't make Line with these dots");
		}
		this.start = start;
		this.end = end;
		if (isTheLineUp == true)
			start.moveUp(true);
		else
			start.moveRight(true);
	}

	@Override
	public void connectDots(Dot first, Dot second, boolean isTheLineUp)
			throws IncorrectInputException {
		if (first != null && second != null && !(first.equals(second))) {
			if (isTheLineUp == true)
				first.moveUp(true);
			else
				first.moveRight(true);
		} else
			throw new IncorrectInputException(
					"can't make line with these dots!");
	}
}
